USE [master]
GO

-- =============================================
-- Author:       Justin Wallace Saunders
-- Create date:  20120330
-- Description:  %TargetDatabaseName% Database Attacher
-- Information:  http://msdn.microsoft.com/en-us/library/ms188031.aspx
-- =============================================
IF NOT EXISTS (SELECT * FROM sys.databases WHERE [Name] = N'%TargetDatabaseName%')
BEGIN
    EXEC sp_attach_db
        @dbname = N'%TargetDatabaseName%',
        @filename1 = N'%TargetDatabaseRoot%\%TargetDatabaseName%.mdf',
        @filename2 = N'%TargetDatabaseRoot%\%TargetDatabaseName%_log.ldf'
END
GO